#!/usr/bin/python
# -*- coding: utf-8 -*-
#file_op.py
#version 0.1  edited by lingyue.wkl 2011-10-1 11:52:11

#this script is userd to operate the file



import os,operator,re

def sorted_Dict_Values(dic):
  keys = dic.keys()
  keys.sort()
  return [dic[key] for key in keys]

#dsu 
def case_insensitive_sort(string_list):
  auxiliary_list = [ ( x.lower(), x) fo x in string_list]
  auxiliary_list.sort()
  return [x[1] for x in auxiliary_list]


def sort_by_attr(seq,attr):
  return sorted(seq,key=operator.attrgetter(attr))

def sort_by_attr_inplace(seq,attr):
  return sorted(key=operator.attrgetter(attr))

def process_all_in_random_order(data,process):
  random.shuffle(data)
  for elem in data:
    process(elem)

def embedded_numbers(s):
  re_digits = re.compile(r'(\d+)')
  pieces = re_digits.split(s)
  pieces[1::2] = map(int,pieces[1::2])
  return pieces

#foo2  <foo10
def sort_string_with_embedded_numbers(alist):
  aux = [ (embedded_numbers(s),s) for s in alist ]
  aux.sort()
  return [ s for __, s in aux]

def qsort(L):
  if len(L) <= 1:
    return L
  return qsort([lt for lt in L[1:] if lt < L[0]) + L[0:1] + \
         qsort([ge for ge in L[1:] if ge >=L[0])

